<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="keywords" content="Hexo Theme Redefine">
    
    <meta name="author" content="星纪">
    <!-- preconnect -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

    
    <!--- Seo Part-->
    
    <link rel="canonical" href="http://example.com/2024/01/21/day01_ajax入门/"/>
    <meta name="robots" content="index,follow">
    <meta name="googlebot" content="index,follow">
    <meta name="revisit-after" content="1 days">
    
        <meta name="description" content="Day01_Ajax入门知识点自测 如下对象取值的方式哪个正确? 123let obj &#x3D; &amp;#123;    name: &amp;#x27;黑马&amp;#x27;&amp;#125;  A: obj.a B: obj()a  答案  A选项正确      哪个赋值会让浏览器解析成标签显示? 12let ul &#x3D; document.querySelector(&amp;#x27;#ul&amp;#x27;)let str &#x3D; &#96;&amp;l">
<meta property="og:type" content="article">
<meta property="og:title" content="Ajax入门">
<meta property="og:url" content="http://example.com/2024/01/21/Day01_AJAX%E5%85%A5%E9%97%A8/index.html">
<meta property="og:site_name" content="星纪">
<meta property="og:description" content="Day01_Ajax入门知识点自测 如下对象取值的方式哪个正确? 123let obj &#x3D; &amp;#123;    name: &amp;#x27;黑马&amp;#x27;&amp;#125;  A: obj.a B: obj()a  答案  A选项正确      哪个赋值会让浏览器解析成标签显示? 12let ul &#x3D; document.querySelector(&amp;#x27;#ul&amp;#x27;)let str &#x3D; &#96;&amp;l">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="http://example.com/images/image-20230403173156484.png">
<meta property="og:image" content="http://example.com/images/image-20230220113157010.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230403185206384.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230403185305934.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230403185356997.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230403185406674.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230403185428276.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230220122455915.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404101257205.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230220125428695.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230220130833363.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404104319428.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404104328384.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404104333584.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404104350387.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230220131753051.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404104440224.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404104447501.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404104508764.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230220132229960.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230220132617016.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404104556531.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230220133141151.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230220133344116.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404104720587.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404104851497.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404104955330.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404105003019.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404105134538.png">
<meta property="og:image" content="http://example.com/images/Ajax-1/image-20230404105141226.png">
<meta property="article:published_time" content="2024-01-21T11:33:33.000Z">
<meta property="article:modified_time" content="2024-01-23T11:38:59.673Z">
<meta property="article:author" content="John">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/images/image-20230403173156484.png">
    
    
    <!--- Icon Part-->
    <link rel="icon" type="image/png" href="/images/redefine-favicon.svg" sizes="192x192">
    <link rel="apple-touch-icon" sizes="180x180" href="/images/redefine-favicon.svg">
    <meta name="theme-color" content="#A31F34">
    <link rel="shortcut icon" href="/images/redefine-favicon.svg">
    <!--- Page Info-->
    
    <title>
        
            Ajax入门 -
        
        星纪
    </title>

    
<link rel="stylesheet" href="/fonts/Chillax/chillax.css">


    
        <style>
    :root {
        --preloader-background-color: #fff;
        --preloader-text-color: #000;
    }

    @media (prefers-color-scheme: dark) {
        :root {
            --preloader-background-color: #202124;
            --preloader-text-color: #fff;
        }
    }

    @media (prefers-color-scheme: light) {
        :root {
            --preloader-background-color: #fff;
            --preloader-text-color: #000;
        }
    }

    @media (max-width: 600px) {
        .ml13 {
            font-size: 2.6rem !important; /* Adjust this value as needed */
        }
    }

    .preloader {
        display: flex;
        flex-direction: column;
        gap: 1rem; /* Tailwind 'gap-4' is 1rem */
        align-items: center;
        justify-content: center;
        position: fixed;
        padding: 12px;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100vw;
        height: 100vh; /* 'h-screen' is 100% of the viewport height */
        background-color: var(--preloader-background-color);
        z-index: 1100; /* 'z-[1100]' sets the z-index */
        transition: opacity 0.2s ease-in-out;
    }

    .ml13 {
        font-size: 3.2rem;
        /* text-transform: uppercase; */
        color: var(--preloader-text-color);
        letter-spacing: -1px;
        font-weight: 500;
        font-family: 'Chillax-Variable', sans-serif;
        text-align: center;
    }

    .ml13 .word {
        display: inline-flex;
        flex-wrap: wrap;
        white-space: nowrap;
    }

    .ml13 .letter {
        display: inline-block;
        line-height: 1em;
    }
</style>

<div class="preloader">
    
<script src="/js/libs/anime.min.js"></script>

    <h1 class="ml13">
        星纪
    </h1>
    <script>
        var textWrapper = document.querySelector('.ml13');
        // Split text into words
        var words = textWrapper.textContent.trim().split(' ');

        // Clear the existing content
        textWrapper.innerHTML = '';

        // Wrap each word and its letters in spans
        words.forEach(function(word) {
            var wordSpan = document.createElement('span');
            wordSpan.classList.add('word');
            wordSpan.innerHTML = word.replace(/\S/g, "<span class='letter'>$&</span>");
            textWrapper.appendChild(wordSpan);
            textWrapper.appendChild(document.createTextNode(' ')); // Add space between words
        });


        anime.timeline({loop: true})
            .add({
                targets: '.ml13 .letter',
                translateY: [100,0],
                translateZ: 0,
                opacity: [0,1],
                easing: "easeOutExpo",
                duration: 1400,
                delay: (el, i) => 300 + 30 * i
            }).add({
            targets: '.ml13 .letter',
            translateY: [0,-100],
            opacity: [1,0],
            easing: "easeInExpo",
            duration: 1200,
            delay: (el, i) => 100 + 30 * i
        });

        let themeStatus = JSON.parse(localStorage.getItem('REDEFINE-THEME-STATUS'))?.isDark;

        // If the theme status is not found in local storage, check the preferred color scheme
        if (themeStatus === undefined || themeStatus === null) {
            if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
                themeStatus = 'dark';
            } else {
                themeStatus = 'light';
            }
        }

        // Now you can use the themeStatus variable in your code
        if (themeStatus) {
            document.documentElement.style.setProperty('--preloader-background-color', '#202124');
            document.documentElement.style.setProperty('--preloader-text-color', '#fff');
        } else {
            document.documentElement.style.setProperty('--preloader-background-color', '#fff');
            document.documentElement.style.setProperty('--preloader-text-color', '#000');
        }

        window.addEventListener('load', function () {
            hidePreloaderAfterTimeout(1000); // Hide after 1000 milliseconds once the window has loaded
        });

        // Backup failsafe: Hide preloader after a maximum of 5000 milliseconds, regardless of the window load event
        hidePreloaderAfterTimeout(5000);

        function hidePreloaderAfterTimeout(delay) {
            setTimeout(function () {
                var preloader = document.querySelector('.preloader');
                preloader.style.opacity = '0';
                setTimeout(function () {
                    preloader.style.display = 'none';
                }, 200);
            }, delay);
        }
    </script>
</div>
    

    
<link rel="stylesheet" href="/css/style.css">


    
        
<link rel="stylesheet" href="/assets/build/styles.css">

    

    
<link rel="stylesheet" href="/fonts/fonts.css">

    
<link rel="stylesheet" href="/fonts/Satoshi/satoshi.css">

    <!--- Font Part-->
    
    
    
    

    <!--- Inject Part-->
    
    <script id="hexo-configurations">
    window.config = {"hostname":"example.com","root":"/","language":"en"};
    window.theme = {"articles":{"style":{"font_size":"16px","line_height":1.5,"image_border_radius":"14px","image_alignment":"center","image_caption":false,"link_icon":true,"title_alignment":"left"},"word_count":{"enable":true,"count":true,"min2read":true},"author_label":{"enable":true,"auto":false,"list":[]},"code_block":{"copy":true,"style":"mac","font":{"enable":false,"family":null,"url":null}},"toc":{"enable":true,"max_depth":3,"number":false,"expand":true,"init_open":true},"copyright":{"enable":true,"default":"cc_by_nc_sa"},"lazyload":true,"recommendation":{"enable":false,"title":"推荐阅读","limit":3,"mobile_limit":2,"placeholder":"/images/wallhaven-wqery6-light.webp","skip_dirs":[]}},"colors":{"primary":"#A31F34","secondary":null},"global":{"fonts":{"chinese":{"enable":false,"family":null,"url":null},"english":{"enable":false,"family":null,"url":null}},"content_max_width":"1000px","sidebar_width":"210px","hover":{"shadow":true,"scale":false},"scroll_progress":{"bar":false,"percentage":true},"website_counter":{"url":"https://cn.vercount.one/js","enable":true,"site_pv":true,"site_uv":true,"post_pv":true},"single_page":true,"preloader":true,"open_graph":true,"google_analytics":{"enable":false,"id":null}},"home_banner":{"enable":true,"style":"fixed","image":{"light":"/images/wallhaven-wqery6-light.webp","dark":"/images/wallhaven-wqery6-dark.webp"},"title":"星纪","subtitle":{"text":[],"hitokoto":{"enable":false,"api":"https://v1.hitokoto.cn"},"typing_speed":100,"backing_speed":80,"starting_delay":500,"backing_delay":1500,"loop":true,"smart_backspace":true},"text_color":{"light":"#fff","dark":"#d1d1b6"},"text_style":{"title_size":"2.8rem","subtitle_size":"1.5rem","line_height":1.2},"custom_font":{"enable":false,"family":null,"url":null},"social_links":{"enable":false,"links":{"github":null,"instagram":null,"zhihu":null,"twitter":null,"email":null},"qrs":{"weixin":null}}},"plugins":{"feed":{"enable":false},"aplayer":{"enable":false,"type":"fixed","audios":[{"name":null,"artist":null,"url":null,"cover":null}]},"mermaid":{"enable":false,"version":"9.3.0"}},"version":"2.6.0","navbar":{"auto_hide":false,"color":{"left":"#f78736","right":"#367df7","transparency":35},"links":{"Home":{"path":"/","icon":"fa-regular fa-house"}},"search":{"enable":false,"preload":true}},"page_templates":{"friends_column":2,"tags_style":"blur"},"home":{"sidebar":{"enable":true,"position":"left","first_item":"menu","announcement":null,"links":null},"article_date_format":"auto","categories":{"enable":true,"limit":3},"tags":{"enable":true,"limit":3}},"footerStart":"2022/8/17 11:45:14"};
    window.lang_ago = {"second":"%s seconds ago","minute":"%s minutes ago","hour":"%s hours ago","day":"%s days ago","week":"%s weeks ago","month":"%s months ago","year":"%s years ago"};
    window.data = {"masonry":false};
  </script>
    
    <!--- Fontawesome Part-->
    
<link rel="stylesheet" href="/fontawesome/fontawesome.min.css">

    
<link rel="stylesheet" href="/fontawesome/brands.min.css">

    
<link rel="stylesheet" href="/fontawesome/solid.min.css">

    
<link rel="stylesheet" href="/fontawesome/regular.min.css">

    
    
    
    
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
<div class="progress-bar-container">
    

    
        <span class="pjax-progress-bar"></span>
<!--        <span class="swup-progress-icon">-->
<!--            <i class="fa-solid fa-circle-notch fa-spin"></i>-->
<!--        </span>-->
    
</div>


<main class="page-container" id="swup">

    

    <div class="main-content-container">


        <div class="main-content-header">
            <header class="navbar-container">

    <div class="navbar-content">
        <div class="left">
            
            <a class="logo-title" href="/">
                
                星纪
                
            </a>
        </div>

        <div class="right">
            <!-- PC -->
            <div class="desktop">
                <ul class="navbar-list">
                    
                        
                            

                            <li class="navbar-item">
                                <!-- Menu -->
                                <a class=""
                                   href="/"
                                        >
                                    <i class="fa-regular fa-house fa-fw"></i>
                                    HOME
                                    
                                </a>

                                <!-- Submenu -->
                                
                            </li>
                    
                    
                </ul>
            </div>
            <!-- Mobile -->
            <div class="mobile">
                
                <div class="icon-item navbar-bar">
                    <div class="navbar-bar-middle"></div>
                </div>
            </div>
        </div>
    </div>

    <!-- Mobile drawer -->
    <div class="navbar-drawer h-screen w-full absolute top-0 left-0 bg-background-color flex flex-col justify-between">
        <ul class="drawer-navbar-list flex flex-col px-4 justify-center items-start">
            
                
                    

                    <li class="drawer-navbar-item text-base my-1.5 flex flex-col w-full">
                        
                        <a class="py-1.5 px-2 flex flex-row items-center justify-between gap-1 hover:!text-primary active:!text-primary text-2xl font-semibold group border-b border-border-color hover:border-primary w-full "
                           href="/"
                        >
                            <span>
                                HOME
                            </span>
                            
                                <i class="fa-regular fa-house fa-sm fa-fw"></i>
                            
                        </a>
                        

                        
                    </li>
            
        </ul>

        <div class="statistics flex justify-around my-2.5">
    <a class="item tag-count-item flex flex-col justify-center items-center w-20" href="/tags">
        <div class="number text-2xl sm:text-xl text-second-text-color font-semibold">0</div>
        <div class="label text-third-text-color text-sm">Tags</div>
    </a>
    <a class="item tag-count-item flex flex-col justify-center items-center w-20" href="/categories">
        <div class="number text-2xl sm:text-xl text-second-text-color font-semibold">0</div>
        <div class="label text-third-text-color text-sm">Categories</div>
    </a>
    <a class="item tag-count-item flex flex-col justify-center items-center w-20" href="/archives">
        <div class="number text-2xl sm:text-xl text-second-text-color font-semibold">9</div>
        <div class="label text-third-text-color text-sm">Posts</div>
    </a>
</div>
    </div>

    <div class="window-mask"></div>

</header>


        </div>

        <div class="main-content-body">

            

            <div class="main-content">

                
                    <div class="post-page-container flex relative justify-between box-border w-full h-full">
    <div class="article-content-container">

        <div class="article-title relative w-full">
            
                <div class="w-full flex items-center pt-6 justify-start">
                    <h1 class="article-title-regular text-second-text-color text-4xl md:text-6xl font-bold px-2 sm:px-6 md:px-8 py-3">Ajax入门</h1>
                </div>
            
            </div>

        
            <div class="article-header flex flex-row gap-2 items-center px-2 sm:px-6 md:px-8">
                <div class="avatar w-[46px] h-[46px] flex-shrink-0 rounded-medium border border-border-color p-[1px]">
                    <img src="/images/redefine-avatar.svg">
                </div>
                <div class="info flex flex-col justify-between">
                    <div class="author flex items-center">
                        <span class="name text-default-text-color text-lg font-semibold">星纪</span>
                        
                            <span class="author-label ml-1.5 text-xs px-2 py-0.5 rounded-small text-third-text-color border border-shadow-color-1">Lv2</span>
                        
                    </div>
                    <div class="meta-info">
                        <div class="article-meta-info">
    <span class="article-date article-meta-item">
        <i class="fa-regular fa-pen-fancy"></i>&nbsp;
        <span class="desktop">2024-01-21 19:33:33</span>
        <span class="mobile">2024-01-21 19:33:33</span>
        <span class="hover-info">Created</span>
    </span>
    
        <span class="article-date article-meta-item">
            <i class="fa-regular fa-wrench"></i>&nbsp;
            <span class="desktop">2024-01-23 19:38:59</span>
            <span class="mobile">2024-01-23 19:38:59</span>
            <span class="hover-info">Updated</span>
        </span>
    

    
    

    
    
    
    
        <span class="article-pv article-meta-item">
            <i class="fa-regular fa-eye"></i>&nbsp;<span id="busuanzi_value_page_pv"></span>
        </span>
    
</div>

                    </div>
                </div>
            </div>
        

        


        <div class="article-content markdown-body px-2 sm:px-6 md:px-8 pb-8">
            <h1 id="Day01-Ajax入门"><a href="#Day01-Ajax入门" class="headerlink" title="Day01_Ajax入门"></a>Day01_Ajax入门</h1><h2 id="知识点自测"><a href="#知识点自测" class="headerlink" title="知识点自测"></a>知识点自测</h2><ol>
<li><p>如下对象取值的方式哪个正确?</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> obj = &#123;</span><br><span class="line">    <span class="attr">name</span>: <span class="string">&#x27;黑马&#x27;</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div>

<p>A: obj.a</p>
<p>B: obj()a</p>
<details>
<summary>答案</summary>
<ul>
<li>A选项正确</li>
</ul>
</details>


</li>
<li><p>哪个赋值会让浏览器解析成标签显示?</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> ul = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;#ul&#x27;</span>)</span><br><span class="line"><span class="keyword">let</span> str = <span class="string">`&lt;span&gt;我是span标签&lt;/span&gt;`</span></span><br></pre></td></tr></table></figure></div>

<p>A: ul.innerText &#x3D; str</p>
<p>B: ul.innerHTML &#x3D; str</p>
<details>
<summary>答案</summary>
<ul>
<li>选择B, innerText会把字符串当做普通文本现在在ul标签之间, innerHTML会试着把字符串解析成标签, 如果是普通文本则显示普通文本字符串</li>
</ul>
</details>


</li>
<li><p>哪个是获取输入框值的方式?</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> theInput = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;#input&#x27;</span>)</span><br></pre></td></tr></table></figure></div>

<p>A: theInput.innerHTML</p>
<p>B: theInput.value</p>
<details>
<summary>答案</summary>
<ul>
<li>答案是B, 表单标签设置或获取值用value属性, 其他标签用innerHTML/innerText, 进行设置/获取</li>
</ul>
</details>


</li>
<li><p>哪个是用于获取标签内容?</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> theP = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;#p&#x27;</span>)</span><br></pre></td></tr></table></figure></div>

<p>A: theP.innerHTML &#x3D; ‘内容’</p>
<p>B: theP.innerHTML</p>
<details>
<summary>答案</summary>
<ul>
<li>答案是B, 单独出现是获取值在原地, 如果看到=这个符号, 是把右侧的值赋予给左侧的属性, 影响标签展示效果</li>
</ul>
</details>


</li>
<li><p>哪个是数组的映射方法？</p>
<p>A: arr.forEach</p>
<p>B: arr.map</p>
<details>
<summary>答案</summary>
<ul>
<li>答案是B</li>
</ul>
</details>


</li>
<li><p>数组转字符串并指定拼接符的是哪个?</p>
<p>A: arr.join()</p>
<p>B: arr.split()</p>
<details>
<summary>答案</summary>
<ul>
<li>答案是A</li>
</ul>
</details>


</li>
<li><p>函数传参的方式哪个是正确的？</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">showAlert</span>(<span class="params">msg, className</span>) &#123;&#125;</span><br></pre></td></tr></table></figure></div>

<p>A：showAlert(‘消息’, ‘类名’)</p>
<p>B：showAlert()</p>
<details>
<summary>答案</summary>
<ul>
<li>答案是A</li>
</ul>
</details>


</li>
<li><p>以下哪套代码可以实现对象属性的简写？</p>
<p>A：</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> username = <span class="string">&#x27;老李&#x27;</span></span><br><span class="line"><span class="keyword">let</span> obj = &#123;</span><br><span class="line">  <span class="attr">username</span>: username</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div>

<p>B：</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> user = <span class="string">&#x27;老李&#x27;</span></span><br><span class="line"><span class="keyword">let</span> obj = &#123;</span><br><span class="line">  <span class="attr">username</span>: user</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div>

<details>
<summary>答案</summary>
<ul>
<li>答案是A</li>
</ul>
</details>


</li>
<li><p>以下代码的值是多少？</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> age = <span class="number">10</span></span><br><span class="line"><span class="keyword">const</span> result = age &gt; <span class="number">18</span> ? <span class="string">&#x27;成年了&#x27;</span> : <span class="string">&#x27;未成年&#x27;</span></span><br></pre></td></tr></table></figure></div>

<p>A：‘成年了’</p>
<p>B：‘未成年’</p>
<details>
<summary>答案</summary>
<ul>
<li>答案是B</li>
</ul>
</details>


</li>
<li><p>以下哪个方法可以添加一个额外类名？</p>
<p>A：标签对象.classList.add()</p>
<p>B：标签对象.classList.contains()</p>
<details>
<summary>答案</summary>
<ul>
<li>答案是A</li>
</ul>
</details></li>
</ol>
<h2 id="目录"><a href="#目录" class="headerlink" title="目录"></a>目录</h2><ul>
<li>AJAX 概念和 axios 使用</li>
<li>认识 URL</li>
<li>URL 查询参数</li>
<li>常用请求方法和数据提交</li>
<li>HTTP协议-报文</li>
<li>接口文档</li>
<li>案例 - 用户登录</li>
<li>form-serialize 插件</li>
</ul>
<h2 id="学习目标"><a href="#学习目标" class="headerlink" title="学习目标"></a>学习目标</h2><ol>
<li>掌握 axios 相关参数，从服务器获取并解析展示数据</li>
<li>掌握接口文档的查看和使用</li>
<li>掌握在浏览器的 network 面板中查看请求和响应的内容</li>
<li>了解请求和响应报文的组成部分</li>
</ol>
<h2 id="01-AJAX-概念和-axios-使用"><a href="#01-AJAX-概念和-axios-使用" class="headerlink" title="01.AJAX 概念和 axios 使用"></a>01.AJAX 概念和 axios 使用</h2><h3 id="目标"><a href="#目标" class="headerlink" title="目标"></a>目标</h3><p>了解 AJAX 概念并掌握 axios 库基本使用</p>
<h3 id="讲解"><a href="#讲解" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>什么是 AJAX ? <a class="link"   target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/Guide/AJAX/Getting_Started" >mdn <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></p>
<ul>
<li><p>使用浏览器的 XMLHttpRequest 对象 与服务器通信</p>
</li>
<li><p>浏览器网页中，使用 AJAX技术（XHR对象）发起获取省份列表数据的请求，服务器代码响应准备好的省份列表数据给前端，前端拿到数据数组以后，展示到网页</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/images/image-20230403173156484.png"
                      alt="image-20230403173156484"
                ></p>
</li>
</ul>
</li>
<li><p>什么是服务器？</p>
<ul>
<li>可以暂时理解为提供数据的一台电脑</li>
</ul>
</li>
<li><p>为何学 AJAX ?</p>
<ul>
<li>以前我们的数据都是写在代码里固定的, 无法随时变化</li>
<li>现在我们的数据可以从服务器上进行获取，让数据变活</li>
</ul>
</li>
<li><p>怎么学 AJAX ?</p>
<ul>
<li>这里使用一个第三方库叫 axios, 后续在学习 XMLHttpRequest 对象了解 AJAX 底层原理</li>
<li>因为 axios 库语法简单，让我们有更多精力关注在与服务器通信上，而且后续 Vue，React 学习中，也使用 axios 库与服务器通信</li>
</ul>
</li>
<li><p>需求：从服务器获取省份列表数据，展示到页面上（体验 axios 语法的使用）</p>
<blockquote>
<p>获取省份列表数据 - 目标资源地址：<a class="link"   target="_blank" rel="noopener" href="http://hmajax.itheima.net/api/province" >http://hmajax.itheima.net/api/province <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></p>
</blockquote>
<ul>
<li><p>完成效果：</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/images/image-20230220113157010.png"
                      alt="image-20230220113157010"
                ></p>
</li>
</ul>
</li>
<li><p>接下来讲解 axios 语法，步骤：</p>
</li>
<li><p>引入 axios.js 文件到自己的网页中</p>
<blockquote>
<p>axios.js文件链接: <a class="link"   target="_blank" rel="noopener" href="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js" >https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></p>
</blockquote>
</li>
<li><p>明确axios函数的使用语法</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">axios</span>(&#123;</span><br><span class="line">  <span class="attr">url</span>: <span class="string">&#x27;目标资源地址&#x27;</span></span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="function">(<span class="params">result</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 对服务器返回的数据做后续处理</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></div>

<blockquote>
<p>注意：请求的 url 地址, 就是标记资源的网址</p>
<p>注意：then 方法这里先体验使用，由来后续会讲到</p>
</blockquote>
</li>
<li><p>对应代码</p>
</li>
</ol>
  <div class="highlight-container" data-rel="Html"><figure class="iseeu highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>AJAX概念和axios使用<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!--</span></span><br><span class="line"><span class="comment">    axios库地址：https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js</span></span><br><span class="line"><span class="comment">    省份数据地址：http://hmajax.itheima.net/api/province</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    目标: 使用axios库, 获取省份列表数据, 展示到页面上</span></span><br><span class="line"><span class="comment">    1. 引入axios库</span></span><br><span class="line"><span class="comment">  --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">&quot;my-p&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    <span class="comment">// 2. 使用axios函数</span></span></span><br><span class="line"><span class="language-javascript">    <span class="title function_">axios</span>(&#123;</span></span><br><span class="line"><span class="language-javascript">      <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/province&#x27;</span></span></span><br><span class="line"><span class="language-javascript">    &#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">console</span>.<span class="title function_">log</span>(result)</span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// 好习惯：多打印，确认属性名</span></span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">console</span>.<span class="title function_">log</span>(result.<span class="property">data</span>.<span class="property">list</span>)</span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">console</span>.<span class="title function_">log</span>(result.<span class="property">data</span>.<span class="property">list</span>.<span class="title function_">join</span>(<span class="string">&#x27;&lt;br&gt;&#x27;</span>))</span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// 把准备好省份列表，插入到页面</span></span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.my-p&#x27;</span>).<span class="property">innerHTML</span> = result.<span class="property">data</span>.<span class="property">list</span>.<span class="title function_">join</span>(<span class="string">&#x27;&lt;br&gt;&#x27;</span>) </span></span><br><span class="line"><span class="language-javascript">    &#125;)</span></span><br><span class="line"><span class="language-javascript">  </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure></div>



<h3 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>AJAX 有什么用？</p>
<details>
<summary>答案</summary>
<ul>
<li>浏览器和服务器之间通信，动态数据交互</li>
</ul>
</details>


</li>
<li><p>AJAX 如何学：</p>
<details>
<summary>答案</summary>
<ul>
<li>先掌握 axios 库使用，再了解 XMLHttpRequest 原理</li>
</ul>
</details>


</li>
<li><p>这一节 axios 体验步骤（语法）？</p>
<details>
<summary>答案</summary>
<ul>
<li>引入 axios 库，使用 axios 相关语法</li>
</ul>
</details></li>
</ol>
<h2 id="02-认识-URL"><a href="#02-认识-URL" class="headerlink" title="02.认识 URL"></a>02.认识 URL</h2><h3 id="目标-1"><a href="#目标-1" class="headerlink" title="目标"></a>目标</h3><p>了解 URL 的组成和作用</p>
<h3 id="讲解-1"><a href="#讲解-1" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>为什么要认识 URL ? <a class="link"   target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/Guide/AJAX/Getting_Started" >mdn <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></p>
<ul>
<li>虽然是后端给我的一个地址，但是哪部分标记的是服务器电脑，哪部分标记的是资源呢？所以为了和服务器有效沟通我们要认识一下</li>
</ul>
</li>
<li><p>什么是 URL ？</p>
<ul>
<li><p>统一资源定位符，简称网址，用于定位网络中的资源（资源指的是：网页，图片，数据，视频，音频等等）</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230403185206384.png"
                      alt="image-20230403185206384"
                ></p>
</li>
</ul>
</li>
<li><p>URL 的组成?</p>
<ul>
<li><p>协议，域名，资源路径（URL 组成有很多部分，我们先掌握这3个重要的部分即可）</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230403185305934.png"
                      alt="image-20230403185305934"
                ></p>
</li>
</ul>
</li>
<li><p>什么是 http 协议 ?</p>
<ul>
<li><p>叫超文本传输协议，规定了浏览器和服务器传递数据的格式（而格式具体有哪些稍后我们就会学到）</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230403185356997.png"
                      alt="image-20230403185356997"
                ></p>
</li>
</ul>
</li>
<li><p>什么是域名 ?</p>
<ul>
<li><p>标记服务器在互联网当中的方位，网络中有很多服务器，你想访问哪一台，就需要知道它的域名才可以</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230403185406674.png"
                      alt="image-20230403185406674"
                ></p>
</li>
</ul>
</li>
<li><p>什么是资源路径 ?</p>
<ul>
<li><p>一个服务器内有多个资源，用于标识你要访问的资源具体的位置</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230403185428276.png"
                      alt="image-20230403185428276"
                ></p>
</li>
</ul>
</li>
<li><p>接下来做个需求，访问新闻列表的 URL 网址，打印新闻数据</p>
<ul>
<li>效果图如下：</li>
</ul>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230220122455915.png"
                      alt="image-20230220122455915"
                ></p>
<blockquote>
<p>新闻列表数据 URL 网址：<a class="link"   target="_blank" rel="noopener" href="http://hmajax.itheima.net/api/news" >http://hmajax.itheima.net/api/news <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></p>
</blockquote>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">axios</span>(&#123;</span><br><span class="line">  <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/news&#x27;</span></span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="variable language_">console</span>.<span class="title function_">log</span>(result)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></div>

<blockquote>
<p>url解释：从黑马服务器使用http协议，访问&#x2F;api&#x2F;news路径下的新闻列表资源</p>
</blockquote>
</li>
</ol>
<h3 id="小结-1"><a href="#小结-1" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>URL 是什么？</p>
<details>
<summary>答案</summary>
<ul>
<li>统一资源定位符，网址，用于访问服务器上资源
</li>
</ul>
</details>


</li>
<li><p>请解释这个 URL，每个部分作用？</p>
<p><a class="link"   target="_blank" rel="noopener" href="http://hmajax.itheima.net/api/news" >http://hmajax.itheima.net/api/news <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></p>
<details>
<summary>答案</summary>
<ul>
<li>协议://域名/资源路径
</li>
</ul>
</details></li>
</ol>
<h2 id="03-URL-查询参数"><a href="#03-URL-查询参数" class="headerlink" title="03.URL 查询参数"></a>03.URL 查询参数</h2><h3 id="目标-2"><a href="#目标-2" class="headerlink" title="目标"></a>目标</h3><p>掌握-通过URL传递查询参数，获取匹配的数据</p>
<h3 id="讲解-2"><a href="#讲解-2" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>什么是查询参数 ?</p>
<ul>
<li><p>携带给服务器额外信息，让服务器返回我想要的某一部分数据而不是全部数据</p>
</li>
<li><p>举例：查询河北省下属的城市列表，需要先把河北省传递给服务器</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404101257205.png"
                      alt="image-20230404101257205"
                ></p>
</li>
</ul>
</li>
<li><p>查询参数的语法 ？</p>
<ul>
<li>在 url 网址后面用?拼接格式：<a class="link"   target="_blank" rel="noopener" href="http://xxxx.com/xxx/xxx?%E5%8F%82%E6%95%B0%E5%90%8D1=%E5%80%BC1&%E5%8F%82%E6%95%B0%E5%90%8D2=%E5%80%BC2" >http://xxxx.com/xxx/xxx?参数名1=值1&amp;参数名2=值2 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li>参数名一般是后端规定的，值前端看情况传递即可</li>
</ul>
</li>
<li><p>axios 如何携带查询参数?</p>
<ul>
<li><p>使用 params 选项即可</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">axios</span>(&#123;</span><br><span class="line">  <span class="attr">url</span>: <span class="string">&#x27;目标资源地址&#x27;</span>,</span><br><span class="line">  <span class="attr">params</span>: &#123;</span><br><span class="line">    参数名: 值</span><br><span class="line">  &#125;</span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 对服务器返回的数据做后续处理</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></div>

<blockquote>
<p>查询城市列表的 url地址：<a class="link"   target="_blank" rel="noopener" href="http://hmajax.itheima.net/api/city?pname=%E6%B2%B3%E5%8C%97%E7%9C%81" >http://hmajax.itheima.net/api/city <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></p>
<p>参数名：pname （值要携带省份名字）</p>
</blockquote>
</li>
</ul>
</li>
<li><p>需求：获取“河北省”下属的城市列表，展示到页面，对应代码：</p>
<div class="highlight-container" data-rel="Html"><figure class="iseeu highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>查询参数<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">    城市列表: http://hmajax.itheima.net/api/city</span></span><br><span class="line"><span class="comment">    参数名: pname</span></span><br><span class="line"><span class="comment">    值: 省份名字</span></span><br><span class="line"><span class="comment">  --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    <span class="title function_">axios</span>(&#123;</span></span><br><span class="line"><span class="language-javascript">      <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/city&#x27;</span>,</span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// 查询参数</span></span></span><br><span class="line"><span class="language-javascript">      <span class="attr">params</span>: &#123;</span></span><br><span class="line"><span class="language-javascript">        <span class="attr">pname</span>: <span class="string">&#x27;辽宁省&#x27;</span></span></span><br><span class="line"><span class="language-javascript">      &#125;</span></span><br><span class="line"><span class="language-javascript">    &#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">console</span>.<span class="title function_">log</span>(result.<span class="property">data</span>.<span class="property">list</span>)</span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;p&#x27;</span>).<span class="property">innerHTML</span> = result.<span class="property">data</span>.<span class="property">list</span>.<span class="title function_">join</span>(<span class="string">&#x27;&lt;br&gt;&#x27;</span>)</span></span><br><span class="line"><span class="language-javascript">    &#125;)</span></span><br><span class="line"><span class="language-javascript">  </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure></div></li>
</ol>
<h3 id="小结-2"><a href="#小结-2" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>URL 查询参数有什么用？</p>
<details>
<summary>答案</summary>
<ul>
<li>浏览器提供给服务器额外信息，获取对应的数据
</li>
</ul>
</details>


</li>
<li><p>axios 要如何携带查询参数？</p>
<details>
<summary>答案</summary>
<ul>
<li>使用 params 选项，携带参数名和值在对象结构中
</li>
</ul>
</details></li>
</ol>
<h2 id="04-案例-查询-地区列表"><a href="#04-案例-查询-地区列表" class="headerlink" title="04.案例-查询-地区列表"></a>04.案例-查询-地区列表</h2><h3 id="目标-3"><a href="#目标-3" class="headerlink" title="目标"></a>目标</h3><p>巩固查询参数的使用，并查看多对查询参数如何传递</p>
<h3 id="讲解-3"><a href="#讲解-3" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>需求：根据输入的省份名字和城市名字，查询下属地区列表</p>
<ul>
<li><p>完成效果如下：</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230220125428695.png"
                      alt="image-20230220125428695"
                ></p>
</li>
<li><p>相关参数</p>
<blockquote>
<p>查询地区: <a class="link"   target="_blank" rel="noopener" href="http://hmajax.itheima.net/api/area" >http://hmajax.itheima.net/api/area <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></p>
<p>参数名：</p>
<p>pname：省份名字</p>
<p>cname：城市名字</p>
</blockquote>
</li>
</ul>
</li>
<li><p>正确代码如下：</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">      获取地区列表: http://hmajax.itheima.net/api/area</span></span><br><span class="line"><span class="comment">      查询参数:</span></span><br><span class="line"><span class="comment">        pname: 省份或直辖市名字</span></span><br><span class="line"><span class="comment">        cname: 城市名字</span></span><br><span class="line"><span class="comment">    */</span></span><br><span class="line"><span class="comment">// 目标: 根据省份和城市名字, 查询地区列表</span></span><br><span class="line"><span class="comment">// 1. 查询按钮-点击事件</span></span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.sel-btn&#x27;</span>).<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">// 2. 获取省份和城市名字</span></span><br><span class="line">    <span class="keyword">let</span> pname = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.province&#x27;</span>).<span class="property">value</span></span><br><span class="line">    <span class="keyword">let</span> cname = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.city&#x27;</span>).<span class="property">value</span></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 3. 基于axios请求地区列表数据</span></span><br><span class="line">    <span class="title function_">axios</span>(&#123;</span><br><span class="line">        <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/area&#x27;</span>,</span><br><span class="line">        <span class="attr">params</span>: &#123;</span><br><span class="line">            pname,</span><br><span class="line">            cname</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="comment">// console.log(result)</span></span><br><span class="line">        <span class="comment">// 4. 把数据转li标签插入到页面上</span></span><br><span class="line">        <span class="keyword">let</span> list = result.<span class="property">data</span>.<span class="property">list</span></span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(list)</span><br><span class="line">        <span class="keyword">let</span> theLi = list.<span class="title function_">map</span>(<span class="function"><span class="params">areaName</span> =&gt;</span> <span class="string">`&lt;li class=&quot;list-group-item&quot;&gt;<span class="subst">$&#123;areaName&#125;</span>&lt;/li&gt;`</span>).<span class="title function_">join</span>(<span class="string">&#x27;&#x27;</span>)</span><br><span class="line">        <span class="variable language_">console</span>.<span class="title function_">log</span>(theLi)</span><br><span class="line">        <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.list-group&#x27;</span>).<span class="property">innerHTML</span> = theLi</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></div></li>
</ol>
<h3 id="小结-3"><a href="#小结-3" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>ES6 对象属性和值简写的前提是什么？</p>
<details>
<summary>答案</summary>
<ul>
<li>当属性名和value位置变量名同名即可简写
</li>
</ul>
</details></li>
</ol>
<h2 id="05-常用请求方法和数据提交"><a href="#05-常用请求方法和数据提交" class="headerlink" title="05.常用请求方法和数据提交"></a>05.常用请求方法和数据提交</h2><h3 id="目标-4"><a href="#目标-4" class="headerlink" title="目标"></a>目标</h3><p>掌握如何向服务器提交数据，而不单单是获取数据</p>
<h3 id="讲解-4"><a href="#讲解-4" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>想要提交数据，先来了解什么是请求方法</p>
<ul>
<li><p>请求方法是一些固定单词的英文，例如：GET，POST，PUT，DELETE，PATCH（这些都是http协议规定的），每个单词对应一种对服务器资源要执行的操作</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230220130833363.png"
                      alt="image-20230220130833363"
                ></p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404104319428.png"
                      alt="image-20230404104319428"
                ></p>
</li>
<li><p>前面我们获取数据其实用的就是GET请求方法，但是axios内部设置了默认请求方法就是GET，我们就没有写</p>
</li>
<li><p>但是提交数据需要使用POST请求方法</p>
</li>
</ul>
</li>
<li><p>什么时候进行数据提交呢？</p>
<ul>
<li><p>例如：多端要查看同一份订单数据，或者使用同一个账号进行登录，那订单&#x2F;用户名+密码，就需要保存在服务器上，随时随地进行访问</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404104328384.png"
                      alt="image-20230404104328384"
                ></p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404104333584.png"
                      alt="image-20230404104333584"
                ></p>
</li>
</ul>
</li>
<li><p>axios 如何提交数据到服务器呢？</p>
<ul>
<li><p>需要学习，method 和 data 这2个新的选项了（大家不用担心，这2个学完，axios常用的选项就都学完了）</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">axios</span>(&#123;</span><br><span class="line">  <span class="attr">url</span>: <span class="string">&#x27;目标资源地址&#x27;</span>,</span><br><span class="line">  <span class="attr">method</span>: <span class="string">&#x27;请求方法&#x27;</span>,</span><br><span class="line">  <span class="attr">data</span>: &#123;</span><br><span class="line">    参数名: 值</span><br><span class="line">  &#125;</span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 对服务器返回的数据做后续处理</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></div></li>
</ul>
</li>
<li><p>需求：注册账号，提交用户名和密码到服务器保存</p>
<blockquote>
<p>注册用户 URL 网址：<a class="link"   target="_blank" rel="noopener" href="http://hmajax.itheima.net/api/register" >http://hmajax.itheima.net/api/register <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></p>
<p>请求方法：POST</p>
<p>参数名：</p>
<p>username：用户名（要求中英文和数字组成，最少8位）</p>
<p>password：密码（最少6位）</p>
</blockquote>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404104350387.png"
                      alt="image-20230404104350387"
                ></p>
</li>
<li><p>正确代码如下：</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">  注册用户：http://hmajax.itheima.net/api/register</span></span><br><span class="line"><span class="comment">  请求方法：POST</span></span><br><span class="line"><span class="comment">  参数名：</span></span><br><span class="line"><span class="comment">    username：用户名（中英文和数字组成，最少8位）</span></span><br><span class="line"><span class="comment">    password：密码  （最少6位）</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">  目标：点击按钮，通过axios提交用户和密码，完成注册</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.btn&#x27;</span>).<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span><br><span class="line">  <span class="title function_">axios</span>(&#123;</span><br><span class="line">    <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/register&#x27;</span>,</span><br><span class="line">    <span class="attr">method</span>: <span class="string">&#x27;POST&#x27;</span>,</span><br><span class="line">    <span class="attr">data</span>: &#123;</span><br><span class="line">      <span class="attr">username</span>: <span class="string">&#x27;itheima007&#x27;</span>,</span><br><span class="line">      <span class="attr">password</span>: <span class="string">&#x27;7654321&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></div></li>
</ol>
<h3 id="小结-4"><a href="#小结-4" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>请求方法最常用的是哪2个，分别有什么作用？</p>
<details>
<summary>答案</summary>
<ul>
<li>POST 提交数据，GET 查询数据
</li>
</ul>
</details>
</li>
<li><p>axios 的核心配置项？</p>
<details>
<summary>答案</summary>
<ul>
<li>url：目标资源地址，method：请求方法，params：查询参数，data：提交的数据
</li>
</ul>
</details></li>
</ol>
<h2 id="06-axios-错误处理"><a href="#06-axios-错误处理" class="headerlink" title="06.axios 错误处理"></a>06.axios 错误处理</h2><h3 id="目标-5"><a href="#目标-5" class="headerlink" title="目标"></a>目标</h3><p>掌握接收 axios 响应错误信息的处理语法</p>
<h3 id="讲解-5"><a href="#讲解-5" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>如果注册相同的用户名，则会遇到注册失败的请求，也就是 axios 请求响应失败了，你会在控制台看到如图的错误：</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230220131753051.png"
                      alt="image-20230220131753051"
                ></p>
</li>
<li><p>在 axios 语法中要如何处理呢？</p>
<ul>
<li>因为，普通用户不会去控制台里看错误信息，我们要编写代码拿到错误并展示给用户在页面上</li>
</ul>
</li>
<li><p>使用 axios 的 catch 方法，捕获这次请求响应的错误并做后续处理，语法如下：</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="title function_">axios</span>(&#123;</span><br><span class="line">  <span class="comment">// ...请求选项</span></span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 处理成功数据</span></span><br><span class="line">&#125;).<span class="title function_">catch</span>(<span class="function"><span class="params">error</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 处理失败错误</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></div>
</li>
<li><p>需求：再次重复注册相同用户名，提示用户注册失败的原因</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404104440224.png"
                      alt="image-20230404104440224"
                ></p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404104447501.png"
                      alt="image-20230404104447501"
                ></p>
</li>
<li><p>对应代码</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.btn&#x27;</span>).<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span><br><span class="line">    <span class="title function_">axios</span>(&#123;</span><br><span class="line">      <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/register&#x27;</span>,</span><br><span class="line">      <span class="attr">method</span>: <span class="string">&#x27;post&#x27;</span>,</span><br><span class="line">      <span class="attr">data</span>: &#123;</span><br><span class="line">        <span class="attr">username</span>: <span class="string">&#x27;itheima007&#x27;</span>,</span><br><span class="line">        <span class="attr">password</span>: <span class="string">&#x27;7654321&#x27;</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span><br><span class="line">      <span class="comment">// 成功</span></span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(result)</span><br><span class="line">    &#125;).<span class="title function_">catch</span>(<span class="function"><span class="params">error</span> =&gt;</span> &#123;</span><br><span class="line">      <span class="comment">// 失败</span></span><br><span class="line">      <span class="comment">// 处理错误信息</span></span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(error)</span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(error.<span class="property">response</span>.<span class="property">data</span>.<span class="property">message</span>)</span><br><span class="line">      <span class="title function_">alert</span>(error.<span class="property">response</span>.<span class="property">data</span>.<span class="property">message</span>)</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></div></li>
</ol>
<h3 id="小结-5"><a href="#小结-5" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>axios 如何拿到请求响应失败的信息？</p>
<details>
<summary>答案</summary>
<ul>
<li>通过 axios 函数调用后，在后面接着调用 .catch 方法捕获
</li>
</ul>
</details></li>
</ol>
<h2 id="07-HTTP-协议-请求报文"><a href="#07-HTTP-协议-请求报文" class="headerlink" title="07.HTTP 协议-请求报文"></a>07.HTTP 协议-请求报文</h2><h3 id="目标-6"><a href="#目标-6" class="headerlink" title="目标"></a>目标</h3><p>了解 HTTP 协议中，请求报文的组成和作用</p>
<h3 id="讲解-6"><a href="#讲解-6" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>首先，HTTP 协议规定了浏览器和服务器返回内容的<span style="color: red;">格式</span></p>
</li>
<li><p>请求报文：是浏览器按照协议规定发送给服务器的内容，例如刚刚注册用户时，发起的请求报文：</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404104508764.png"
                      alt="image-20230404104508764"
                ></p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230220132229960.png"
                      alt="image-20230220132229960"
                ></p>
</li>
<li><p>这里的格式包含：</p>
<ul>
<li>请求行：请求方法，URL，协议</li>
<li>请求头：以键值对的格式携带的附加信息，比如：Content-Type（指定了本次传递的内容类型）</li>
<li>空行：分割请求头，空行之后的是发送给服务器的资源</li>
<li>请求体：发送的资源</li>
</ul>
</li>
<li><p>我们切换到浏览器中，来看看刚才注册用户发送的这个请求报文以及内容去哪里查看呢</p>
</li>
<li><p>代码：直接在上个代码基础上复制，然后运行查看请求报文对应关系即可</p>
</li>
</ol>
<h3 id="小结-6"><a href="#小结-6" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>浏览器发送给服务器的内容叫做，请求报文</p>
</li>
<li><p>请求报文的组成是什么？</p>
<details>
<summary>答案</summary>
<ul>
<li>请求行，请求头，空行，请求体
</li>
</ul>
</details>
</li>
<li><p>通过 Chrome 的网络面板如何查看请求体？</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230220132617016.png"
                      alt="image-20230220132617016"
                ></p>
</li>
</ol>
<h2 id="08-请求报文-错误排查"><a href="#08-请求报文-错误排查" class="headerlink" title="08.请求报文-错误排查"></a>08.请求报文-错误排查</h2><h3 id="目标-7"><a href="#目标-7" class="headerlink" title="目标"></a>目标</h3><p>了解学习了查看请求报文之后的作用，可以用来辅助错误排查</p>
<h3 id="讲解-7"><a href="#讲解-7" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li>学习了查看请求报文有什么用呢？<ul>
<li>可以用来确认我们代码发送的请求数据是否真的正确</li>
</ul>
</li>
<li>配套模板代码里，对应 08 标题文件夹里是我同桌的代码，它把登录也写完了，但是无法登录，我们来到模板代码中，找到运行后，在<span style="color: red;">不逐行查看代码的情况下</span>，查看请求报文，看看它登录提交的相关信息对不对，帮他找找问题出现的原因</li>
<li>发现请求体数据有问题，往代码中定位，找到类名写错误了</li>
<li>代码：在配套文件夹素材里，找到需要对应代码，直接运行，根据报错信息，找到错误原因</li>
</ol>
<h3 id="小结-7"><a href="#小结-7" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>学会了查看请求报文，对实际开发有什么帮助呢？</p>
<details>
<summary>答案</summary>
<ul>
<li>可以快速确认我们发送的内容是否正确
</li>
</ul>
</details></li>
</ol>
<h2 id="09-HTTP-协议-响应报文"><a href="#09-HTTP-协议-响应报文" class="headerlink" title="09.HTTP 协议-响应报文"></a>09.HTTP 协议-响应报文</h2><h3 id="目标-8"><a href="#目标-8" class="headerlink" title="目标"></a>目标</h3><p>了解响应报文的组成</p>
<h3 id="讲解-8"><a href="#讲解-8" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>响应报文：是服务器按照协议固定的格式，返回给浏览器的内容</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404104556531.png"
                      alt="image-20230404104556531"
                ></p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230220133141151.png"
                      alt="image-20230220133141151"
                ></p>
</li>
<li><p>响应报文的组成：</p>
<ul>
<li>响应行（状态行）：协议，HTTP响应状态码，状态信息</li>
<li>响应头：以键值对的格式携带的附加信息，比如：Content-Type（告诉浏览器，本次返回的内容类型）</li>
<li>空行：分割响应头，控制之后的是服务器返回的资源</li>
<li>响应体：返回的资源</li>
</ul>
</li>
<li><p>HTTP 响应状态码：</p>
<ul>
<li><p>用来表明请求是否成功完成</p>
</li>
<li><p>例如：404（客户端要找的资源，在服务器上不存在）</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230220133344116.png"
                      alt="image-20230220133344116"
                ></p>
</li>
</ul>
</li>
</ol>
<h3 id="小结-8"><a href="#小结-8" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>响应报文的组成？</p>
<details>
<summary>答案</summary>
<ul>
<li>响应行，响应头，空行，响应体
</li>
</ul>
</details>
</li>
<li><p>HTTP 响应状态码是做什么的？</p>
<details>
<summary>答案</summary>
<ul>
<li>表明请求是否成功完成，2xx都是成功的
</li>
</ul>
</details></li>
</ol>
<h2 id="10-接口文档"><a href="#10-接口文档" class="headerlink" title="10.接口文档"></a>10.接口文档</h2><h3 id="目标-9"><a href="#目标-9" class="headerlink" title="目标"></a>目标</h3><p>掌握接口文档的使用，配合 axios 与服务器进行数据交互</p>
<h3 id="讲解-9"><a href="#讲解-9" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>接口文档：描述接口的文章（一般是后端工程师，编写和提供）</p>
</li>
<li><p>接口：指的使用 AJAX 和 服务器通讯时，使用的 URL，请求方法，以及参数，例如：<a class="link"   target="_blank" rel="noopener" href="https://apifox.com/apidoc/shared-1b0dd84f-faa8-435d-b355-5a8a329e34a8" >AJAX阶段接口文档 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></p>
</li>
<li><p>例如：获取城市列表接口样子</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404104720587.png"
                      alt="image-20230404104720587"
                ></p>
</li>
<li><p>需求：打开 AJAX 阶段接口文档，查看登录接口，并编写代码，完成一次登录的效果吧</p>
</li>
<li><p>代码如下：</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.btn&#x27;</span>).<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 用户登录</span></span><br><span class="line">  <span class="title function_">axios</span>(&#123;</span><br><span class="line">    <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/login&#x27;</span>,</span><br><span class="line">    <span class="attr">method</span>: <span class="string">&#x27;post&#x27;</span>,</span><br><span class="line">    <span class="attr">data</span>: &#123;</span><br><span class="line">      <span class="attr">username</span>: <span class="string">&#x27;itheima007&#x27;</span>,</span><br><span class="line">      <span class="attr">password</span>: <span class="string">&#x27;7654321&#x27;</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></div></li>
</ol>
<h3 id="小结-9"><a href="#小结-9" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>接口文档是什么？</p>
<details>
<summary>答案</summary>
<ul>
<li>由后端提供的描述接口的文章
</li>
</ul>
</details>
</li>
<li><p>接口文档里包含什么？</p>
<details>
<summary>答案</summary>
<ul>
<li>请求的 URL 网址，请求方法，请求参数和说明
</li>
</ul>
</details></li>
</ol>
<h2 id="11-案例-用户登录-主要业务"><a href="#11-案例-用户登录-主要业务" class="headerlink" title="11.案例-用户登录-主要业务"></a>11.案例-用户登录-主要业务</h2><h3 id="目标-10"><a href="#目标-10" class="headerlink" title="目标"></a>目标</h3><p>尝试通过页面获取用户名和密码，进行登录</p>
<h3 id="讲解-10"><a href="#讲解-10" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>先来到备课代码中，运行完成的页面，查看要完成的登录效果（登录成功和失败）</p>
</li>
<li><p>需求：编写代码，查看接口文档，填写相关信息，完成登录业务</p>
</li>
<li><p>分析实现的步骤</p>
<ol>
<li><p>点击登录，获取并判断用户名和长度</p>
</li>
<li><p>提交数据和服务器通信</p>
</li>
<li><p>提示信息，反馈给用户（这节课先来完成前 2 个步骤）</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404104851497.png"
                      alt="image-20230404104851497"
                ></p>
</li>
</ol>
</li>
<li><p>代码如下：</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 目标1：点击登录时，用户名和密码长度判断，并提交数据和服务器通信</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 1.1 登录-点击事件</span></span><br><span class="line"><span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.btn-login&#x27;</span>).<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span><br><span class="line">  <span class="comment">// 1.2 获取用户名和密码</span></span><br><span class="line">  <span class="keyword">const</span> username = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.username&#x27;</span>).<span class="property">value</span></span><br><span class="line">  <span class="keyword">const</span> password = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.password&#x27;</span>).<span class="property">value</span></span><br><span class="line">  <span class="comment">// console.log(username, password)</span></span><br><span class="line"></span><br><span class="line">  <span class="comment">// 1.3 判断长度</span></span><br><span class="line">  <span class="keyword">if</span> (username.<span class="property">length</span> &lt; <span class="number">8</span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;用户名必须大于等于8位&#x27;</span>)</span><br><span class="line">    <span class="keyword">return</span> <span class="comment">// 阻止代码继续执行</span></span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">if</span> (password.<span class="property">length</span> &lt; <span class="number">6</span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;密码必须大于等于6位&#x27;</span>)</span><br><span class="line">    <span class="keyword">return</span> <span class="comment">// 阻止代码继续执行</span></span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 1.4 基于axios提交用户名和密码</span></span><br><span class="line">  <span class="comment">// console.log(&#x27;提交数据到服务器&#x27;)</span></span><br><span class="line">  <span class="title function_">axios</span>(&#123;</span><br><span class="line">    <span class="attr">url</span>: <span class="string">&#x27;http://hmajax.itheima.net/api/login&#x27;</span>,</span><br><span class="line">    <span class="attr">method</span>: <span class="string">&#x27;POST&#x27;</span>,</span><br><span class="line">    <span class="attr">data</span>: &#123;</span><br><span class="line">      username,</span><br><span class="line">      password</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;).<span class="title function_">then</span>(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(result)</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(result.<span class="property">data</span>.<span class="property">message</span>)</span><br><span class="line">  &#125;).<span class="title function_">catch</span>(<span class="function"><span class="params">error</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(error)</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(error.<span class="property">response</span>.<span class="property">data</span>.<span class="property">message</span>)</span><br><span class="line">  &#125;)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure></div></li>
</ol>
<h3 id="小结-10"><a href="#小结-10" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>总结下用户登录案例的思路？</p>
<details>
<summary>答案</summary>
<ul>
<li>1. 登录按钮-绑定点击事件
2. 从页面输入框里，获取用户名和密码
3. 判断长度是否符合要求
4. 基于 axios 提交用户名和密码
</li>
</ul>
</details></li>
</ol>
<h2 id="12-案例-用户登录-提示信息"><a href="#12-案例-用户登录-提示信息" class="headerlink" title="12.案例-用户登录-提示信息"></a>12.案例-用户登录-提示信息</h2><h3 id="目标-11"><a href="#目标-11" class="headerlink" title="目标"></a>目标</h3><p>根据准备好的提示标签和样式，给用户反馈提示</p>
<h3 id="讲解-11"><a href="#讲解-11" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>需求：使用提前准备好的提示框，来把登录成功&#x2F;失败结果提示给用户</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404104955330.png"
                      alt="image-20230404104955330"
                ></p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404105003019.png"
                      alt="image-20230404105003019"
                ></p>
</li>
<li><p>使用提示框，反馈提示消息，因为有4处地方需要提示框，所以封装成函数</p>
<ol>
<li><p>获取提示框</p>
</li>
<li><p>封装提示框函数，重复调用，满足提示需求</p>
<p>功能：</p>
<ol>
<li>显示提示框</li>
<li>不同提示文字msg，和成功绿色失败红色isSuccess参数（true成功，false失败）</li>
<li>过2秒后，让提示框自动消失</li>
</ol>
</li>
</ol>
</li>
<li><p>对应提示框核心代码：</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 2.2 封装提示框函数，重复调用，满足提示需求</span></span><br><span class="line"><span class="comment"> * 功能：</span></span><br><span class="line"><span class="comment"> * 1. 显示提示框</span></span><br><span class="line"><span class="comment"> * 2. 不同提示文字msg，和成功绿色失败红色isSuccess（true成功，false失败）</span></span><br><span class="line"><span class="comment"> * 3. 过2秒后，让提示框自动消失</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">alertFn</span>(<span class="params">msg, isSuccess</span>) &#123;</span><br><span class="line">  <span class="comment">// 1&gt; 显示提示框</span></span><br><span class="line">  myAlert.<span class="property">classList</span>.<span class="title function_">add</span>(<span class="string">&#x27;show&#x27;</span>)</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 2&gt; 实现细节</span></span><br><span class="line">  myAlert.<span class="property">innerText</span> = msg</span><br><span class="line">  <span class="keyword">const</span> bgStyle = isSuccess ? <span class="string">&#x27;alert-success&#x27;</span> : <span class="string">&#x27;alert-danger&#x27;</span></span><br><span class="line">  myAlert.<span class="property">classList</span>.<span class="title function_">add</span>(bgStyle)</span><br><span class="line"></span><br><span class="line">  <span class="comment">// 3&gt; 过2秒隐藏</span></span><br><span class="line">  <span class="built_in">setTimeout</span>(<span class="function">() =&gt;</span> &#123;</span><br><span class="line">    myAlert.<span class="property">classList</span>.<span class="title function_">remove</span>(<span class="string">&#x27;show&#x27;</span>)</span><br><span class="line">    <span class="comment">// 提示：避免类名冲突，重置背景色</span></span><br><span class="line">    myAlert.<span class="property">classList</span>.<span class="title function_">remove</span>(bgStyle)</span><br><span class="line">  &#125;, <span class="number">2000</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></div></li>
</ol>
<h3 id="小结-11"><a href="#小结-11" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>我们什么时候需要封装函数？</p>
<details>
<summary>答案</summary>
<ul>
<li>遇到相同逻辑，重复代码要复用的时候
</li>
</ul>
</details>
</li>
<li><p>如何封装一个函数呢？</p>
<details>
<summary>答案</summary>
<ul>
<li>先明确要完成的需求，以及需要的参数，再来实现其中的细节，然后在需要的地方调用
</li>
</ul>
</details>
</li>
<li><p>我们的提示框是如何控制出现&#x2F;隐藏的？</p>
<details>
<summary>答案</summary>
<ul>
<li>添加或移除显示的类名即可
</li>
</ul>
</details></li>
</ol>
<h2 id="13-form-serialize-插件"><a href="#13-form-serialize-插件" class="headerlink" title="13.form-serialize 插件"></a>13.form-serialize 插件</h2><h3 id="目标-12"><a href="#目标-12" class="headerlink" title="目标"></a>目标</h3><p>使用 form-serialize 插件，快速收集目标表单范围内表单元素的值</p>
<h3 id="讲解-12"><a href="#讲解-12" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>我们前面收集表单元素的值，是一个个标签获取的</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404105134538.png"
                      alt="image-20230404105134538"
                ></p>
</li>
<li><p>如果一套表单里有很多很多表单元素，如何一次性快速收集出来呢？</p>
<p><img  
                     lazyload
                     src="/images/loading.svg"
                     data-src="/../images/Ajax-1/image-20230404105141226.png"
                      alt="image-20230404105141226"
                ></p>
</li>
<li><p>使用 form-serialize 插件提供的 serialize 函数就可以办到</p>
</li>
<li><p>form-serialize 插件语法：</p>
<ol>
<li><p>引入 form-serialize 插件到自己网页中</p>
</li>
<li><p>使用 serialize 函数</p>
<ul>
<li><p>参数1：要获取的 form 表单标签对象（要求表单元素需要有 name 属性-用来作为收集的数据中属性名）</p>
</li>
<li><p>参数2：配置对象</p>
<ul>
<li>hash：<ul>
<li>true - 收集出来的是一个 JS 对象结构</li>
<li>false - 收集出来的是一个查询字符串格式</li>
</ul>
</li>
<li>empty：<ul>
<li>true - 收集空值</li>
<li>false - 不收集空值</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ol>
</li>
<li><p>需求：收集登录表单里用户名和密码</p>
</li>
<li><p>对应代码：</p>
<div class="highlight-container" data-rel="Html"><figure class="iseeu highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;!DOCTYPE <span class="keyword">html</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">html</span> <span class="attr">lang</span>=<span class="string">&quot;en&quot;</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">head</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">&quot;UTF-8&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">http-equiv</span>=<span class="string">&quot;X-UA-Compatible&quot;</span> <span class="attr">content</span>=<span class="string">&quot;IE=edge&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">meta</span> <span class="attr">name</span>=<span class="string">&quot;viewport&quot;</span> <span class="attr">content</span>=<span class="string">&quot;width=device-width, initial-scale=1.0&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">title</span>&gt;</span>form-serialize插件使用<span class="tag">&lt;/<span class="name">title</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">head</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">form</span> <span class="attr">action</span>=<span class="string">&quot;javascript:;&quot;</span> <span class="attr">class</span>=<span class="string">&quot;example-form&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">name</span>=<span class="string">&quot;username&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;text&quot;</span> <span class="attr">name</span>=<span class="string">&quot;password&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">br</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">input</span> <span class="attr">type</span>=<span class="string">&quot;button&quot;</span> <span class="attr">class</span>=<span class="string">&quot;btn&quot;</span> <span class="attr">value</span>=<span class="string">&quot;提交&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">form</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!-- </span></span><br><span class="line"><span class="comment">    目标：在点击提交时，使用form-serialize插件，快速收集表单元素值</span></span><br><span class="line"><span class="comment">    1. 把插件引入到自己网页中</span></span><br><span class="line"><span class="comment">  --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;./lib/form-serialize.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">script</span>&gt;</span><span class="language-javascript"></span></span><br><span class="line"><span class="language-javascript">    <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.btn&#x27;</span>).<span class="title function_">addEventListener</span>(<span class="string">&#x27;click&#x27;</span>, <span class="function">() =&gt;</span> &#123;</span></span><br><span class="line"><span class="language-javascript">      <span class="comment">/**</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       * 2. 使用serialize函数，快速收集表单元素的值</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       * 参数1：要获取哪个表单的数据</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *  表单元素设置name属性，值会作为对象的属性名</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *  建议name属性的值，最好和接口文档参数名一致</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       * 参数2：配置对象</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *  hash 设置获取数据结构</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *    - true：JS对象（推荐）一般请求体里提交给服务器</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *    - false: 查询字符串</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *  empty 设置是否获取空值</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *    - true: 获取空值（推荐）数据结构和标签结构一致</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">       *    - false：不获取空值</span></span></span><br><span class="line"><span class="comment"><span class="language-javascript">      */</span></span></span><br><span class="line"><span class="language-javascript">      <span class="keyword">const</span> form = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.example-form&#x27;</span>)</span></span><br><span class="line"><span class="language-javascript">      <span class="keyword">const</span> data = <span class="title function_">serialize</span>(form, &#123; <span class="attr">hash</span>: <span class="literal">true</span>, <span class="attr">empty</span>: <span class="literal">true</span> &#125;)</span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// const data = serialize(form, &#123; hash: false, empty: true &#125;)</span></span></span><br><span class="line"><span class="language-javascript">      <span class="comment">// const data = serialize(form, &#123; hash: true, empty: false &#125;)</span></span></span><br><span class="line"><span class="language-javascript">      <span class="variable language_">console</span>.<span class="title function_">log</span>(data)</span></span><br><span class="line"><span class="language-javascript">    &#125;)</span></span><br><span class="line"><span class="language-javascript">  </span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;/<span class="name">html</span>&gt;</span></span><br></pre></td></tr></table></figure></div></li>
</ol>
<h3 id="小结-12"><a href="#小结-12" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>我们什么时候使用 form-serialize 插件？</p>
<details>
<summary>答案</summary>
<ul>
<li>快速收集表单元素的值</li>
</ul>
</details>
</li>
<li><p>如何使用 form-serialize 插件？</p>
<details>
<summary>答案</summary>
<ul>
<li>1. 先引入插件到自己的网页中，2. 准备form和表单元素的name属性，3.使用serialize函数，传入form表单和配置对象
</li>
</ul>
</details>
</li>
<li><p>配置对象中 hash 和 empty 有什么用？</p>
<details>
<summary>答案</summary>
<ul>
<li>hash 决定是收集为 JS 对象还是查询参数字符串，empty 决定是否收集空值
</li>
</ul>
</details></li>
</ol>
<h2 id="14-案例-用户登录-form-serialize"><a href="#14-案例-用户登录-form-serialize" class="headerlink" title="14.案例-用户登录-form-serialize"></a>14.案例-用户登录-form-serialize</h2><h3 id="目标-13"><a href="#目标-13" class="headerlink" title="目标"></a>目标</h3><p>尝试通过 form-serialize 重新修改用户登录案例-收集用户名和密码</p>
<h3 id="讲解-13"><a href="#讲解-13" class="headerlink" title="讲解"></a>讲解</h3><ol>
<li><p>基于模板代码，使用 form-serialize 插件来收集用户名和密码</p>
</li>
<li><p>在原来的代码基础上修改即可</p>
<ol>
<li><p>先引入插件</p>
<div class="highlight-container" data-rel="Html"><figure class="iseeu highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 3.1 引入插件 --&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;./lib/form-serialize.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure></div>
</li>
<li><p>然后修改代码</p>
<div class="highlight-container" data-rel="Js"><figure class="iseeu highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 3.2 使用serialize函数，收集登录表单里用户名和密码</span></span><br><span class="line"><span class="keyword">const</span> form = <span class="variable language_">document</span>.<span class="title function_">querySelector</span>(<span class="string">&#x27;.login-form&#x27;</span>)</span><br><span class="line"><span class="keyword">const</span> data = <span class="title function_">serialize</span>(form, &#123; <span class="attr">hash</span>: <span class="literal">true</span>, <span class="attr">empty</span>: <span class="literal">true</span> &#125;)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(data)</span><br><span class="line"><span class="comment">// &#123;username: &#x27;itheima007&#x27;, password: &#x27;7654321&#x27;&#125;</span></span><br><span class="line"><span class="keyword">const</span> &#123; username, password &#125; = data</span><br></pre></td></tr></table></figure></div></li>
</ol>
</li>
</ol>
<h3 id="小结-13"><a href="#小结-13" class="headerlink" title="小结"></a>小结</h3><ol>
<li><p>如何把一个第三方插件使用在已完成的案例中？</p>
<details>
<summary>答案</summary>
<ul>
<li>引入后，只需要使用在要修改的地方，修改一点就要确认测试一下
</li>
</ul>
</details></li>
</ol>
<h2 id="今日重点-必须会"><a href="#今日重点-必须会" class="headerlink" title="今日重点(必须会)"></a>今日重点(必须会)</h2><ol>
<li>axios 的配置项有哪几个，作用分别是什么？</li>
<li>接口文档都包含哪些信息？</li>
<li>在浏览器中如何查看查询参数&#x2F;请求体，以及响应体数据？</li>
<li>请求报文和响应报文由几个部分组成，每个部分的作用？</li>
</ol>
<h2 id="今日作业-必完成"><a href="#今日作业-必完成" class="headerlink" title="今日作业(必完成)"></a>今日作业(必完成)</h2><p>参考作业文件夹的md要求</p>
<h2 id="参考文献"><a href="#参考文献" class="headerlink" title="参考文献"></a>参考文献</h2><ol>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E5%AE%A2%E6%88%B7%E7%AB%AF/101081?fr=aladdin" >客户端-&gt;百度百科 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E6%B5%8F%E8%A7%88%E5%99%A8/213911?fr=aladdin" >浏览器解释-&gt;百度百科 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E6%9C%8D%E5%8A%A1%E5%99%A8/100571?fr=aladdin" >服务器解释-&gt;百度百科 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E7%BB%9F%E4%B8%80%E8%B5%84%E6%BA%90%E5%AE%9A%E4%BD%8D%E7%B3%BB%E7%BB%9F/5937042?fromtitle=URL&fromid=110640&fr=aladdin" >url解释-&gt;百度百科 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/item/HTTP?fromtitle=HTTP%E5%8D%8F%E8%AE%AE&fromid=1276942" >http协议-&gt;百度百科 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E4%B8%BB%E6%9C%BA%E5%90%8D" >主机名-&gt;百度百科 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E7%AB%AF%E5%8F%A3%E5%8F%B" >端口号-&gt;百度百科 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/tashuo/browse/content?id=11fca6ecdc2c066af4c5594f&lemmaId=8425&fromLemmaModule=pcBottom&lemmaTitle=ajax" >Ajax解释-&gt;百度-懂啦 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://developer.mozilla.org/zh-CN/docs/Web/Guide/AJAX/Getting_Started" >Ajax解释-&gt;MDN解释Ajax是与服务器通信而不只是请求 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/item/axios" >axios-&gt;百度(可以点击播报听读音) <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://github.com/axios/axios" >axios(github)地址 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://axios-http.com/" >axios官方推荐官网 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://www.npmjs.com/package/axios" >axios(npmjs)地址 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/item/post/2171305" >GET和POST区别-&gt;百度百科 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E6%8A%A5%E6%96%87/3164352" >报文讲解-&gt;百度百科 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/item/HTTP%E7%8A%B6%E6%80%81%E7%A0%81/5053660" >HTTP状态码-&gt;百度百科 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
<li><a class="link"   target="_blank" rel="noopener" href="https://baike.baidu.com/item/%E6%8E%A5%E5%8F%A3/2886384" >接口概念-&gt;百度百科 <i class="fa-regular fa-arrow-up-right-from-square fa-sm"></i></a></li>
</ol>

        </div>

        
            <div class="post-copyright-info w-full my-8 px-2 sm:px-6 md:px-8">
                <div class="article-copyright-info-container">
    <ul>
        <li><strong>Title:</strong> Ajax入门</li>
        <li><strong>Author:</strong> 星纪</li>
        <li><strong>Created at
                :</strong> 2024-01-21 19:33:33</li>
        
            <li>
                <strong>Updated at
                    :</strong> 2024-01-23 19:38:59
            </li>
        
        <li>
            <strong>Link:</strong> https://redefine.ohevan.com/2024/01/21/Day01_AJAX入门/
        </li>
        <li>
            <strong>
                License:
            </strong>
            

            
                This work is licensed under <a class="license" target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0">CC BY-NC-SA 4.0</a>.
            
        </li>
    </ul>
</div>

            </div>
        

        

        

        
            <div class="article-nav my-8 flex justify-between items-center px-2 sm:px-6 md:px-8">
                
                    <div class="article-prev border-border-color shadow-redefine-flat shadow-shadow-color-2 rounded-medium px-4 py-2 hover:shadow-redefine-flat-hover hover:shadow-shadow-color-2">
                        <a class="prev"
                        rel="prev"
                        href="/2024/01/21/%E7%AC%AC%E4%BA%8C%E7%AF%87%E5%8D%9A%E5%AE%A2Vue%E5%9F%BA%E7%A1%80/"
                        >
                            <span class="left arrow-icon flex justify-center items-center">
                                <i class="fa-solid fa-chevron-left"></i>
                            </span>
                            <span class="title flex justify-center items-center">
                                <span class="post-nav-title-item">第二篇博客-Vue基础</span>
                                <span class="post-nav-item">Prev posts</span>
                            </span>
                        </a>
                    </div>
                
                
                    <div class="article-next border-border-color shadow-redefine-flat shadow-shadow-color-2 rounded-medium px-4 py-2 hover:shadow-redefine-flat-hover hover:shadow-shadow-color-2">
                        <a class="next"
                        rel="next"
                        href="/2024/01/21/Day02_AJAX%E7%BB%BC%E5%90%88%E6%A1%88%E4%BE%8B/"
                        >
                            <span class="title flex justify-center items-center">
                                <span class="post-nav-title-item">Ajax综合案例</span>
                                <span class="post-nav-item">Next posts</span>
                            </span>
                            <span class="right arrow-icon flex justify-center items-center">
                                <i class="fa-solid fa-chevron-right"></i>
                            </span>
                        </a>
                    </div>
                
            </div>
        


        
            <div class="comment-container px-2 sm:px-6 md:px-8 pb-8">
                <div class="comments-container mt-10 w-full ">
    <div id="comment-anchor" class="w-full h-2.5"></div>
    <div class="comment-area-title w-full my-1.5 md:my-2.5 text-xl md:text-3xl font-bold">
        Comments
    </div>
    

        
            
    <div id="waline"></div>
    <script type="module" data-swup-reload-script>
      import { init } from '/js/libs/waline.mjs';

      function loadWaline() {
        init({
          el: '#waline',
          serverURL: 'https://example.example.com',
          lang: 'zh-CN',
          dark: 'body[class~="dark-mode"]',
          requiredMeta: ['nick', 'mail'],
          emoji: [],
          recaptchaV3Key: "wasd",
          
        });
      }

      if (typeof swup !== 'undefined') {
        loadWaline();
      } else {
        window.addEventListener('DOMContentLoaded', loadWaline);
      }
    </script>



        
    
</div>

            </div>
        
    </div>

    
        <div class="toc-content-container">
            <div class="post-toc-wrap">
    <div class="post-toc">
        <div class="toc-title">On this page</div>
        <div class="page-title">Ajax入门</div>
        <ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Day01-Ajax%E5%85%A5%E9%97%A8"><span class="nav-text">Day01_Ajax入门</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%9F%A5%E8%AF%86%E7%82%B9%E8%87%AA%E6%B5%8B"><span class="nav-text">知识点自测</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%9B%AE%E5%BD%95"><span class="nav-text">目录</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%AD%A6%E4%B9%A0%E7%9B%AE%E6%A0%87"><span class="nav-text">学习目标</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#01-AJAX-%E6%A6%82%E5%BF%B5%E5%92%8C-axios-%E4%BD%BF%E7%94%A8"><span class="nav-text">01.AJAX 概念和 axios 使用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#02-%E8%AE%A4%E8%AF%86-URL"><span class="nav-text">02.认识 URL</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-1"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-1"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-1"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#03-URL-%E6%9F%A5%E8%AF%A2%E5%8F%82%E6%95%B0"><span class="nav-text">03.URL 查询参数</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-2"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-2"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-2"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#04-%E6%A1%88%E4%BE%8B-%E6%9F%A5%E8%AF%A2-%E5%9C%B0%E5%8C%BA%E5%88%97%E8%A1%A8"><span class="nav-text">04.案例-查询-地区列表</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-3"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-3"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-3"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#05-%E5%B8%B8%E7%94%A8%E8%AF%B7%E6%B1%82%E6%96%B9%E6%B3%95%E5%92%8C%E6%95%B0%E6%8D%AE%E6%8F%90%E4%BA%A4"><span class="nav-text">05.常用请求方法和数据提交</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-4"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-4"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-4"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#06-axios-%E9%94%99%E8%AF%AF%E5%A4%84%E7%90%86"><span class="nav-text">06.axios 错误处理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-5"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-5"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-5"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#07-HTTP-%E5%8D%8F%E8%AE%AE-%E8%AF%B7%E6%B1%82%E6%8A%A5%E6%96%87"><span class="nav-text">07.HTTP 协议-请求报文</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-6"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-6"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-6"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#08-%E8%AF%B7%E6%B1%82%E6%8A%A5%E6%96%87-%E9%94%99%E8%AF%AF%E6%8E%92%E6%9F%A5"><span class="nav-text">08.请求报文-错误排查</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-7"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-7"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-7"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#09-HTTP-%E5%8D%8F%E8%AE%AE-%E5%93%8D%E5%BA%94%E6%8A%A5%E6%96%87"><span class="nav-text">09.HTTP 协议-响应报文</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-8"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-8"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-8"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#10-%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3"><span class="nav-text">10.接口文档</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-9"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-9"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-9"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#11-%E6%A1%88%E4%BE%8B-%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95-%E4%B8%BB%E8%A6%81%E4%B8%9A%E5%8A%A1"><span class="nav-text">11.案例-用户登录-主要业务</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-10"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-10"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-10"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#12-%E6%A1%88%E4%BE%8B-%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95-%E6%8F%90%E7%A4%BA%E4%BF%A1%E6%81%AF"><span class="nav-text">12.案例-用户登录-提示信息</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-11"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-11"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-11"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#13-form-serialize-%E6%8F%92%E4%BB%B6"><span class="nav-text">13.form-serialize 插件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-12"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-12"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-12"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#14-%E6%A1%88%E4%BE%8B-%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95-form-serialize"><span class="nav-text">14.案例-用户登录-form-serialize</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%9B%AE%E6%A0%87-13"><span class="nav-text">目标</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%AE%B2%E8%A7%A3-13"><span class="nav-text">讲解</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B0%8F%E7%BB%93-13"><span class="nav-text">小结</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%8A%E6%97%A5%E9%87%8D%E7%82%B9-%E5%BF%85%E9%A1%BB%E4%BC%9A"><span class="nav-text">今日重点(必须会)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%8A%E6%97%A5%E4%BD%9C%E4%B8%9A-%E5%BF%85%E5%AE%8C%E6%88%90"><span class="nav-text">今日作业(必完成)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%82%E8%80%83%E6%96%87%E7%8C%AE"><span class="nav-text">参考文献</span></a></li></ol></li></ol>

    </div>
</div>
        </div>
    
</div>



                

            </div>

            

        </div>

        <div class="main-content-footer">
            <footer class="footer mt-5 py-5 h-auto text-base text-third-text-color relative border-t-2 border-t-border-color">
    <div class="info-container py-3 text-center">
        
        <div class="text-center">
            &copy;
            
              <span>2022</span>
              -
            
            2024&nbsp;&nbsp;<i class="fa-solid fa-heart fa-beat" style="--fa-animation-duration: 0.5s; color: #f54545"></i>&nbsp;&nbsp;<a href="/">星纪</a>
        </div>
        
            <script data-swup-reload-script src="https://cn.vercount.one/js"></script>
            <div class="relative text-center lg:absolute lg:right-[20px] lg:top-1/2 lg:-translate-y-1/2 lg:text-right">
                
                    <span id="busuanzi_container_site_uv" class="lg:!block">
                        <span class="text-sm">VISITOR COUNT</span>
                        <span id="busuanzi_value_site_uv"></span>
                    </span>
                
                
                    <span id="busuanzi_container_site_pv" class="lg:!block">
                        <span class="text-sm">TOTAL PAGE VIEWS</span>
                        <span id="busuanzi_value_site_pv"></span>
                    </span>
                
            </div>
        
        <div class="relative text-center lg:absolute lg:left-[20px] lg:top-1/2 lg:-translate-y-1/2 lg:text-left">
            <span class="lg:block text-sm">POWERED BY <?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg class="relative top-[2px] inline-block align-baseline" version="1.1" id="圖層_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="1rem" height="1rem" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve"><path fill="#0E83CD" d="M256.4,25.8l-200,115.5L56,371.5l199.6,114.7l200-115.5l0.4-230.2L256.4,25.8z M349,354.6l-18.4,10.7l-18.6-11V275H200v79.6l-18.4,10.7l-18.6-11v-197l18.5-10.6l18.5,10.8V237h112v-79.6l18.5-10.6l18.5,10.8V354.6z"/></svg><a target="_blank" class="text-base" href="https://hexo.io">Hexo</a></span>
            <span class="text-sm lg:block">THEME&nbsp;<a class="text-base" target="_blank" href="https://github.com/EvanNotFound/hexo-theme-redefine">Redefine v2.6.0</a></span>
        </div>
        
        
            <div>
                Blog up for <span class="odometer" id="runtime_days" ></span> days <span class="odometer" id="runtime_hours"></span> hrs <span class="odometer" id="runtime_minutes"></span> Min <span class="odometer" id="runtime_seconds"></span> Sec
            </div>
        
        
            <script data-swup-reload-script>
                try {
                    function odometer_init() {
                    const elements = document.querySelectorAll('.odometer');
                    elements.forEach(el => {
                        new Odometer({
                            el,
                            format: '( ddd).dd',
                            duration: 200
                        });
                    });
                    }
                    odometer_init();
                } catch (error) {}
            </script>
        
        
        
    </div>  
</footer>
        </div>
    </div>

    
        <div class="post-tools">
            <div class="post-tools-container">
    <ul class="article-tools-list">
        <!-- TOC aside toggle -->
        
            <li class="right-bottom-tools page-aside-toggle">
                <i class="fa-regular fa-outdent"></i>
            </li>
        

        <!-- go comment -->
        
            <li class="go-comment">
                <i class="fa-regular fa-comments"></i>
            </li>
        
    </ul>
</div>

        </div>
    

    <div class="right-side-tools-container">
        <div class="side-tools-container">
    <ul class="hidden-tools-list">
        <li class="right-bottom-tools tool-font-adjust-plus flex justify-center items-center">
            <i class="fa-regular fa-magnifying-glass-plus"></i>
        </li>

        <li class="right-bottom-tools tool-font-adjust-minus flex justify-center items-center">
            <i class="fa-regular fa-magnifying-glass-minus"></i>
        </li>

        <li class="right-bottom-tools tool-dark-light-toggle flex justify-center items-center">
            <i class="fa-regular fa-moon"></i>
        </li>

        <!-- rss -->
        

        

        <li class="right-bottom-tools tool-scroll-to-bottom flex justify-center items-center">
            <i class="fa-regular fa-arrow-down"></i>
        </li>
    </ul>

    <ul class="visible-tools-list">
        <li class="right-bottom-tools toggle-tools-list flex justify-center items-center">
            <i class="fa-regular fa-cog fa-spin"></i>
        </li>
        
            <li class="right-bottom-tools tool-scroll-to-top flex justify-center items-center">
                <i class="arrow-up fas fa-arrow-up"></i>
                <span class="percent"></span>
            </li>
        
        
    </ul>
</div>

    </div>

    <div class="image-viewer-container">
    <img src="">
</div>


    

</main>


    
<script src="/js/libs/Swup.min.js"></script>

<script src="/js/libs/SwupSlideTheme.min.js"></script>

<script src="/js/libs/SwupScriptsPlugin.min.js"></script>

<script src="/js/libs/SwupProgressPlugin.min.js"></script>

<script src="/js/libs/SwupScrollPlugin.min.js"></script>

<script src="/js/libs/SwupPreloadPlugin.min.js"></script>

<script>
    const swup = new Swup({
        plugins: [
            new SwupScriptsPlugin({
                optin: true,
            }),
            new SwupProgressPlugin(),
            new SwupScrollPlugin({
                offset: 80,
            }),
            new SwupSlideTheme({
                mainElement: ".main-content-body",
            }),
            new SwupPreloadPlugin(),
        ],
        containers: ["#swup"],
    });
</script>







<script src="/js/tools/imageViewer.js" type="module"></script>

<script src="/js/utils.js" type="module"></script>

<script src="/js/main.js" type="module"></script>

<script src="/js/layouts/navbarShrink.js" type="module"></script>

<script src="/js/tools/scrollTopBottom.js" type="module"></script>

<script src="/js/tools/lightDarkSwitch.js" type="module"></script>

<script src="/js/layouts/categoryList.js" type="module"></script>





    
<script src="/js/tools/codeBlock.js" type="module"></script>




    
<script src="/js/layouts/lazyload.js" type="module"></script>




    
<script src="/js/tools/runtime.js"></script>

    
<script src="/js/libs/odometer.min.js"></script>

    
<link rel="stylesheet" href="/assets/odometer-theme-minimal.css">




  
<script src="/js/libs/Typed.min.js"></script>

  
<script src="/js/plugins/typed.js" type="module"></script>









<div class="post-scripts" data-swup-reload-script>
    
        
<script src="/js/tools/tocToggle.js" type="module"></script>

<script src="/js/layouts/toc.js" type="module"></script>

<script src="/js/plugins/tabs.js" type="module"></script>

    
</div>


</body>
</html>
